package com.mj.app.common_util.picasso;

import android.net.Uri;
import android.widget.ImageView;

import com.mj.app.common_util.BaseApplication;
import com.mj.app.common_util.R;
import com.squareup.picasso.Picasso;

import java.io.File;

/**
 * ========================================
 * picasso 加载图片二次封装
 * Created by David on 2017/10/5.
 * ========================================
 */

public class ImageLoader {

    public static void load(Uri uri, ImageView imageView) {
        load(uri, imageView, R.drawable.ic_launcher);
    }

    public static void load(Uri uri, ImageView imageView, int defaultId) {
        Picasso.with(BaseApplication.getContext()).load(uri).error(defaultId).into(imageView);
    }

    public static void load(File file, ImageView imageView) {
        load(file, imageView, R.drawable.ic_launcher);
    }

    public static void load(File file, ImageView imageView, int defaultId) {

        Picasso.with(BaseApplication.getContext()).load(file).error(defaultId).into(imageView);
    }

    public static void load(String url, ImageView imageView, int defaultId) {
        if(url == null || "".equals(url))
            url = "xxx";
        Picasso.with(BaseApplication.getContext()).load(url).error(defaultId).into(imageView);
    }

    public static void loadWithResId(int resId, ImageView imageView, int defaultId){
        Picasso.with(BaseApplication.getContext()).load(resId).error(defaultId).into(imageView);
    }

    public static void loadCornerWithResId(int resId, ImageView imageView, int defaultId){
        Picasso.with(BaseApplication.getContext()).load(resId).transform(new CircleTransform()).error(defaultId).into(imageView);
    }

    public static void load(String url, ImageView imageView) {
        load(url, imageView, R.drawable.ic_launcher);
    }
}
